package cn.gok;

import java.util.Objects;

class Student{
    private int sid;
    private String sname;
    private String sex;
    private int age;

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student(int sid, String sname, String sex, int age) {
        this.sid = sid;
        this.sname = sname;
        this.sex = sex;
        this.age = age;
    }

    //重写equals后比较的就不是内存地址而是结果值
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return sid == student.sid &&
                Objects.equals(sname, student.sname);

    }

    @Override
    public int hashCode() {
        return Objects.hash(sid, sname);
    }
}

public class equals的重写 {
    public static void main(String[] args) {
        Student student1 = new Student(1,"giao","男",38);
        Student student2 = new Student(1,"giao","女",38);
        System.out.println(student1.equals(student2));
    }

}
